/*
 * =====================================================================================
 *
 *       Filename:  convert.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015/06/07 19时11分59秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Liu Yi (), swliuyi@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include  <fstream>
#include  <vector>

using namespace std;

void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)
{
    std::string::size_type pos1, pos2;
    pos2 = s.find(c);
    pos1 = 0;
    while(std::string::npos != pos2)
    {
        v.push_back(s.substr(pos1, pos2-pos1));
        pos1 = pos2 + c.size();
        pos2 = s.find(c, pos1);
    }
    if(pos1 != s.length())
      v.push_back(s.substr(pos1));
}

void DelKey(string & str)
{
    if(str.size() == 0) return;
    int i = 0,j = 0;
    while(j < str.size())
    {
        str[i] = str[j];
        if(str[i] != '/' )//&& str[i] != '[' && str[i] != ']')
        {
            i++;
        }
        j++;
    }
    str = str.substr(0,i);
}

int main(int argc, char *argv[])
{
    if( argc < 3 )
    {
        cout<<"./this input output"<<endl;
        return 1;
    }
    ifstream file(argv[1]);
    ofstream out(argv[2]);
    string line;
    while(getline(file, line))
    {
        DelKey(line);
        vector<string> wordList;
        SplitString(line, wordList, " ");
        string res;
        for( size_t i = 0; i < wordList.size() ; i++ )
        {
            if( wordList[i] == "[nr" || wordList[i] == "[ns" || wordList[i] == "[nt")
            {
                string tag = wordList[i].substr(1, 2);
                size_t j  = i + 2;
                if( j < wordList.size() && wordList[j] == "]" )//_U
                {
                    res += wordList[i+1];
                    res += "/";
                    res += tag;
                    res += "_U ";
                    i = j;
                    continue;
                }
                if( j < wordList.size() && wordList[j] != "]" )//_B
                {
                    res += wordList[i+1];
                    res += "/";
                    res += tag;
                    res += "_B ";
                }
                j = i + 2;
                while( j + 1 < wordList.size() && wordList[j+1] != "]" )//_I
                {
                    res += wordList[j];
                    res += "/";
                    res += tag;
                    res += "_I ";
                    j++;
                }
                if( j + 1 < wordList.size() && wordList[j + 1] == "]")//_L
                {
                    res += wordList[j];
                    res += "/";
                    res += tag;
                    res += "_L ";
                    i = j + 1;
                }
            }
            else
            {
                res += wordList[i];
                res += "/O ";
            }
        }
        out<<res<<endl;
    }
}
